<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    Es6_one.md |  Small Bridge
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/main.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

<link rel="alternate" href="/atom.xml" title="Small Bridge" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-Es6-one-md" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Es6_one.md
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/14/Es6-one-md/" class="article-date">
  <time datetime="2020-05-14T13:03:14.000Z" itemprop="datePublished">2020-05-14</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/JavaScript/">JavaScript</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">4.1k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">18分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      


      

      
      <p>@<a href="ES6知识补充1">TOC</a></p>
<a id="more"></a>
<h1 id="解构赋值"><a href="#解构赋值" class="headerlink" title="解构赋值"></a>解构赋值</h1><ol>
<li>在数组的解构中，解构的目标若为可遍历对象，皆可进行解构赋值。可遍历对象就是实现Iterator接口的数据<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> [a, b, c, d, e] = <span class="string">'hello'</span>;</span><br><span class="line"><span class="comment">// a = 'h'</span></span><br><span class="line"><span class="comment">// b = 'e'</span></span><br><span class="line"><span class="comment">// c = 'l'</span></span><br><span class="line"><span class="comment">// d = 'l'</span></span><br><span class="line"><span class="comment">// e = 'o'</span></span><br></pre></td></tr></table></figure></li>
<li>当解构模式没有匹配结果，或者匹配结果为undefined，会触发默认值作为解构结果<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> [a = <span class="number">2</span>] = [<span class="literal">undefined</span>]; <span class="comment">// a = 2</span></span><br><span class="line"><span class="keyword">let</span> [a = <span class="number">3</span>, b = a] = [];     <span class="comment">// a = 3, b = 3</span></span><br><span class="line"><span class="keyword">let</span> [a = <span class="number">3</span>, b = a] = [<span class="number">1</span>];    <span class="comment">// a = 1, b = 1</span></span><br><span class="line"><span class="keyword">let</span> [a = <span class="number">3</span>, b = a] = [<span class="number">1</span>, <span class="number">2</span>]; <span class="comment">// a = 1, b = 2</span></span><br></pre></td></tr></table></figure>
<h1 id="Map对象"><a href="#Map对象" class="headerlink" title="Map对象"></a>Map对象</h1></li>
<li>Map对象保存键值对，任何值都可以作为一个键或者一个值</li>
<li>Map对象和Objects的区别</li>
</ol>
<ul>
<li>一个 Object 的键只能是字符串或者 Symbols，但一个 Map 的键可以是任意值。</li>
<li>Map 中的键值是有序的（FIFO 原则），而添加到对象中的键则不是。</li>
<li>Map 的键值对个数可以从 size 属性获取，而 Object 的键值对个数只能手动计算。</li>
<li>Object 都有自己的原型，原型链上的键名有可能和你自己在对象上的设置的键名产生冲突。</li>
</ul>
<ol start="3">
<li>遍历</li>
</ol>
<ul>
<li>for…of<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myMap = <span class="keyword">new</span> <span class="built_in">Map</span>();</span><br><span class="line">myMap.set(<span class="number">0</span>, <span class="string">"zero"</span>);</span><br><span class="line">myMap.set(<span class="number">1</span>, <span class="string">"one"</span>);</span><br><span class="line"> </span><br><span class="line"><span class="comment">// 将会显示两个 log。 一个是 "0 = zero" 另一个是 "1 = one"</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> [key, value] <span class="keyword">of</span> myMap) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(key + <span class="string">" = "</span> + value);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> [key, value] <span class="keyword">of</span> myMap.entries()) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(key + <span class="string">" = "</span> + value);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 这个 entries 方法返回一个新的 Iterator 对象，它按插入顺序包含了 Map 对象中每个元素的 [key, value] 数组。 */</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 将会显示两个log。 一个是 "0" 另一个是 "1"</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> key <span class="keyword">of</span> myMap.keys()) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(key);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 这个 keys 方法返回一个新的 Iterator 对象， 它按插入顺序包含了 Map 对象中每个元素的键。 */</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 将会显示两个log。 一个是 "zero" 另一个是 "one"</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> value <span class="keyword">of</span> myMap.values()) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(value);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 这个 values 方法返回一个新的 Iterator 对象，它按插入顺序包含了 Map 对象中每个元素的值。 */</span></span><br></pre></td></tr></table></figure></li>
<li>forEach()<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myMap = <span class="keyword">new</span> <span class="built_in">Map</span>();</span><br><span class="line">myMap.set(<span class="number">0</span>, <span class="string">"zero"</span>);</span><br><span class="line">myMap.set(<span class="number">1</span>, <span class="string">"one"</span>);</span><br><span class="line"> </span><br><span class="line"><span class="comment">// 将会显示两个 logs。 一个是 "0 = zero" 另一个是 "1 = one"</span></span><br><span class="line">myMap.forEach(<span class="function"><span class="keyword">function</span>(<span class="params">value, key</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(key + <span class="string">" = "</span> + value);</span><br><span class="line">&#125;, myMap)</span><br></pre></td></tr></table></figure></li>
</ul>
<ol start="4">
<li>Map对象的操作</li>
</ol>
<ul>
<li>Map与Array的转换<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> kvArray = [[<span class="string">"key1"</span>, <span class="string">"value1"</span>], [<span class="string">"key2"</span>, <span class="string">"value2"</span>]];</span><br><span class="line"> </span><br><span class="line"><span class="comment">// Map 构造函数可以将一个 二维 键值对数组转换成一个 Map 对象</span></span><br><span class="line"><span class="keyword">var</span> myMap = <span class="keyword">new</span> <span class="built_in">Map</span>(kvArray);</span><br><span class="line"> </span><br><span class="line"><span class="comment">// 使用 Array.from 函数可以将一个 Map 对象转换成一个二维键值对数组</span></span><br><span class="line"><span class="keyword">var</span> outArray = <span class="built_in">Array</span>.from(myMap);</span><br></pre></td></tr></table></figure></li>
<li>Map的克隆<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myMap1 = <span class="keyword">new</span> <span class="built_in">Map</span>([[<span class="string">"key1"</span>, <span class="string">"value1"</span>], [<span class="string">"key2"</span>, <span class="string">"value2"</span>]]);</span><br><span class="line"><span class="keyword">var</span> myMap2 = <span class="keyword">new</span> <span class="built_in">Map</span>(myMap1);</span><br><span class="line"> </span><br><span class="line"><span class="built_in">console</span>.log(myMap1 === myMap2); </span><br><span class="line"><span class="comment">// 打印 false。 Map 对象构造函数生成实例，迭代出新的对象。</span></span><br></pre></td></tr></table></figure></li>
<li>Map的合并<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> first = <span class="keyword">new</span> <span class="built_in">Map</span>([[<span class="number">1</span>, <span class="string">'one'</span>], [<span class="number">2</span>, <span class="string">'two'</span>], [<span class="number">3</span>, <span class="string">'three'</span>],]);</span><br><span class="line"><span class="keyword">var</span> second = <span class="keyword">new</span> <span class="built_in">Map</span>([[<span class="number">1</span>, <span class="string">'uno'</span>], [<span class="number">2</span>, <span class="string">'dos'</span>]]);</span><br><span class="line"> </span><br><span class="line"><span class="comment">// 合并两个 Map 对象时，如果有重复的键值，则后面的会覆盖前面的，对应值即 uno，dos， three</span></span><br><span class="line"><span class="keyword">var</span> merged = <span class="keyword">new</span> <span class="built_in">Map</span>([...first, ...second]);</span><br></pre></td></tr></table></figure>
<h1 id="Set对象"><a href="#Set对象" class="headerlink" title="Set对象"></a>Set对象</h1></li>
</ul>
<ol>
<li>Set 对象允许你存储任何类型的唯一值，无论是原始值或者是对象引用</li>
<li>Set中的特殊值<br>Set 对象存储的值总是唯一的，所以需要判断两个值是否恒等。有几个特殊值需要特殊对待：</li>
</ol>
<ul>
<li>+0 与 -0 在存储判断唯一性的时候是恒等的，所以不重复；</li>
<li>undefined 与 undefined 是恒等的，所以不重复；</li>
<li>NaN 与 NaN 是不恒等的，但是在 Set 中只能存一个，不重复</li>
</ul>
<ol start="3">
<li>Set对象的作用</li>
</ol>
<ul>
<li>数组去重<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> mySet = <span class="keyword">new</span> <span class="built_in">Set</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">4</span>]);</span><br><span class="line">[...mySet]; <span class="comment">// [1, 2, 3, 4]</span></span><br></pre></td></tr></table></figure></li>
<li>求数组的并集<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>];</span><br><span class="line"><span class="keyword">let</span> b = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>];</span><br><span class="line"><span class="keyword">let</span> union = <span class="built_in">Array</span>.from(<span class="keyword">new</span> <span class="built_in">Set</span>([...a,...b]));</span><br><span class="line"><span class="built_in">console</span>.log(union);</span><br></pre></td></tr></table></figure></li>
<li>求数组的交集<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="built_in">Set</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</span><br><span class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> <span class="built_in">Set</span>([<span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>]);</span><br><span class="line"><span class="keyword">var</span> intersect = <span class="keyword">new</span> <span class="built_in">Set</span>([...a].filter(<span class="function"><span class="params">x</span> =&gt;</span> b.has(x))); <span class="comment">// &#123;2, 3&#125;</span></span><br></pre></td></tr></table></figure></li>
<li>求数组的差集<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="built_in">Set</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</span><br><span class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> <span class="built_in">Set</span>([<span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>]);</span><br><span class="line"><span class="keyword">var</span> difference = <span class="keyword">new</span> <span class="built_in">Set</span>([...a].filter(<span class="function"><span class="params">x</span> =&gt;</span> !b.has(x))); <span class="comment">// &#123;1&#125;</span></span><br></pre></td></tr></table></figure>
<h1 id="ES6-字符串"><a href="#ES6-字符串" class="headerlink" title="ES6 字符串"></a>ES6 字符串</h1></li>
</ul>
<ol>
<li>拓展的方法—-子串的识别<br>ES6 之前判断字符串是否包含子串，用 indexOf 方法，ES6 新增了子串的识别方法：</li>
</ol>
<ul>
<li>includes()：返回布尔值，判断是否找到参数字符串</li>
<li>startsWith()：返回布尔值，判断参数字符串是否在原字符串的头部</li>
<li>endsWith()：返回布尔值，判断参数字符串是否在原字符串的尾部<br>以上三个方法都可以接受两个参数，需要搜索的字符串，和可选的搜索起始位置索引,但不能传入正则表达式<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> string = <span class="string">"apple,banana,orange"</span>;</span><br><span class="line">string.includes(<span class="string">"banana"</span>);     <span class="comment">// true</span></span><br><span class="line">string.startsWith(<span class="string">"apple"</span>);    <span class="comment">// true</span></span><br><span class="line">string.endsWith(<span class="string">"apple"</span>);      <span class="comment">// false</span></span><br><span class="line">string.startsWith(<span class="string">"banana"</span>,<span class="number">6</span>)  <span class="comment">// true</span></span><br></pre></td></tr></table></figure></li>
</ul>
<ol start="2">
<li>字符串重复repeat(),表示将字符串重复指定次数返回<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"Hello"</span>.repeat(<span class="number">3.2</span>); <span class="comment">//向下取整，3次</span></span><br><span class="line"><span class="string">"Hello"</span>.repeat(<span class="number">-0.5</span>);<span class="comment">//0次</span></span><br><span class="line"><span class="string">"Hello"</span>.repeat(<span class="literal">NaN</span>);<span class="comment">//0次</span></span><br><span class="line"><span class="string">"Hello"</span>.repeat(<span class="number">-1</span>);<span class="comment">//报错</span></span><br><span class="line"><span class="string">"Hello"</span>.repeat(<span class="string">"2"</span>);<span class="comment">//2次</span></span><br></pre></td></tr></table></figure></li>
<li>字符串补全</li>
</ol>
<ul>
<li>padStart：返回新的字符串，表示用参数字符串从头部补全原字符串</li>
<li>padEnd：返回新的字符串，表示用参数字符串从尾部补全原字符串</li>
<li>接收两个参数，第一个指定生成的字符串的最小长度，第二个是用来补全的字符串，未指定默认空格填充<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="string">"h"</span>.padStart(<span class="number">5</span>,<span class="string">"o"</span>));  <span class="comment">// "ooooh"</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"h"</span>.padEnd(<span class="number">5</span>,<span class="string">"o"</span>));    <span class="comment">// "hoooo"</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"h"</span>.padStart(<span class="number">5</span>));      <span class="comment">// "    h"</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//如果指定的长度小于或者等于原字符串的长度，则返回原字符串</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"hello"</span>.padStart(<span class="number">5</span>,<span class="string">"A"</span>));  <span class="comment">// "hello"</span></span><br><span class="line"><span class="comment">//如果原字符串加上补全字符串长度大于指定长度，则截去超出位数的补全字符串</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"hello"</span>.padEnd(<span class="number">10</span>,<span class="string">",world!"</span>));  <span class="comment">// "hello,worl"</span></span><br><span class="line"><span class="comment">//常用于补全位数</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"123"</span>.padStart(<span class="number">10</span>,<span class="string">"0"</span>));  <span class="comment">// "0000000123"</span></span><br></pre></td></tr></table></figure></li>
</ul>
<ol start="4">
<li>模板字符串</li>
</ol>
<ul>
<li>标签模板：是一个函数调用，其中调用的参数是模板字符串<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">alert<span class="string">`Hello world!`</span>;</span><br><span class="line"><span class="comment">// 等价于</span></span><br><span class="line">alert(<span class="string">'Hello world!'</span>);</span><br></pre></td></tr></table></figure></li>
<li>当模板字符串中带有变量时，会将模板字符串参数处理成多个参数<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params">stringArr,...values</span>)</span>&#123;</span><br><span class="line"> <span class="keyword">let</span> result = <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span>;i&lt;stringArr.length;i++)&#123;</span><br><span class="line">  result += stringArr[i];</span><br><span class="line">  <span class="keyword">if</span>(values[i])&#123;</span><br><span class="line">   result += values[i];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> name = <span class="string">'Mike'</span>;</span><br><span class="line"><span class="keyword">let</span> age = <span class="number">27</span>;</span><br><span class="line">f<span class="string">`My Name is <span class="subst">$&#123;name&#125;</span>,I am <span class="subst">$&#123;age+<span class="number">1</span>&#125;</span> years old next year.`</span>;</span><br><span class="line"><span class="comment">// "My Name is Mike,I am 28 years old next year."</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">//f`My Name is $&#123;name&#125;,I am $&#123;age+1&#125; years old next year.`;</span></span><br><span class="line"><span class="comment">// 等价于</span></span><br><span class="line"><span class="comment">//f(['My Name is',',I am ',' years old next year.'],'Mike',28);</span></span><br></pre></td></tr></table></figure>
通常用于过滤HTML字符串，防止用户输入恶意内容<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params">stringArr,...values</span>)</span>&#123;</span><br><span class="line"> <span class="keyword">let</span> result = <span class="string">""</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span>;i&lt;stringArr.length;i++)&#123;</span><br><span class="line">  result += stringArr[i];</span><br><span class="line">   <span class="keyword">if</span>(values[i])&#123;</span><br><span class="line">     result += <span class="built_in">String</span>(values[i]).replace(<span class="regexp">/&amp;/g</span>, <span class="string">"&amp;amp;"</span>)</span><br><span class="line">               .replace(<span class="regexp">/&lt;/g</span>, <span class="string">"&amp;lt;"</span>)</span><br><span class="line">               .replace(<span class="regexp">/&gt;/g</span>, <span class="string">"&amp;gt;"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br><span class="line">name = <span class="string">'&lt;Amy&amp;MIke&gt;'</span>;</span><br><span class="line">f<span class="string">`&lt;p&gt;Hi, <span class="subst">$&#123;name&#125;</span>.I would like send you some message.&lt;/p&gt;`</span>;</span><br><span class="line"><span class="comment">// &lt;p&gt;Hi, &amp;lt;Amy&amp;amp;MIke&amp;gt;.I would like send you some message.&lt;/p&gt;</span></span><br></pre></td></tr></table></figure>
<h1 id="ES6-数值"><a href="#ES6-数值" class="headerlink" title="ES6 数值"></a>ES6 数值</h1></li>
</ul>
<ol>
<li>常量 Number.EPSILON 接近于2的-52次方</li>
<li>0b(0B) 表示二进制前缀，0o(0O)表示八进制前缀</li>
<li>最大/最小安全整数<br>JS能够精确表示的整数范围 2的-53次方~2的53次方<br>Number.MAX_SAFE_INTEGER    2的53次方-1<br>Number.MIN_SAFE_INTEGER    -(2的53次方-1)</li>
<li>Number对象新方法 Number.isFinite()<br>用于检查一个数值是否是有限的<br>没有隐式的Number类型转换，所有非数值都返回false</li>
<li>从全局移植到Number对象上的方法<br>parseInt    parseFloat   isInteger  isSafeInteger<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 不指定进制时默认为 10 进制</span></span><br><span class="line"><span class="built_in">Number</span>.parseInt(<span class="string">'12.34'</span>); <span class="comment">// 12</span></span><br><span class="line"><span class="built_in">Number</span>.parseInt(<span class="number">12.34</span>);   <span class="comment">// 12</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 指定进制</span></span><br><span class="line"><span class="built_in">Number</span>.parseInt(<span class="string">'0011'</span>,<span class="number">2</span>); <span class="comment">// 3</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 与全局的 parseInt() 函数是同一个函数</span></span><br><span class="line"><span class="built_in">Number</span>.parseInt === <span class="built_in">parseInt</span>; <span class="comment">// true</span></span><br><span class="line"><span class="built_in">Number</span>.parseFloat()</span><br><span class="line">用于把一个字符串解析成浮点数。</span><br><span class="line"><span class="built_in">Number</span>.parseFloat(<span class="string">'123.45'</span>)    <span class="comment">// 123.45</span></span><br><span class="line"><span class="built_in">Number</span>.parseFloat(<span class="string">'123.45abc'</span>) <span class="comment">// 123.45</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 无法被解析成浮点数，则返回 NaN</span></span><br><span class="line"><span class="built_in">Number</span>.parseFloat(<span class="string">'abc'</span>) <span class="comment">// NaN</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 与全局的 parseFloat() 方法是同一个方法</span></span><br><span class="line"><span class="built_in">Number</span>.parseFloat === <span class="built_in">parseFloat</span> <span class="comment">// true</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger()</span><br><span class="line">用于判断给定的参数是否为整数。</span><br><span class="line"><span class="built_in">Number</span>.isInteger(value)</span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">0</span>); <span class="comment">// true</span></span><br><span class="line"><span class="comment">// JavaScript 内部，整数和浮点数采用的是同样的储存方法,因此 1 与 1.0 被视为相同的值</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">1</span>);   <span class="comment">// true</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">1.0</span>); <span class="comment">// true</span></span><br><span class="line"> </span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">1.1</span>);     <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="built_in">Math</span>.PI); <span class="comment">// false</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// NaN 和正负 Infinity 不是整数</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="literal">NaN</span>);       <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="literal">Infinity</span>);  <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(-<span class="literal">Infinity</span>); <span class="comment">// false</span></span><br><span class="line"> </span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="string">"10"</span>);  <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="literal">true</span>);  <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="literal">false</span>); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger([<span class="number">1</span>]);   <span class="comment">// false</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 数值的精度超过 53 个二进制位时，由于第 54 位及后面的位被丢弃，会产生误判</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">1.0000000000000001</span>) <span class="comment">// true</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 一个数值的绝对值小于 Number.MIN_VALUE（5E-324），即小于 JavaScript 能够分辨</span></span><br><span class="line"><span class="comment">// 的最小值，会被自动转为 0，也会产生误判</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">5E-324</span>); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isInteger(<span class="number">5E-325</span>); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">Number</span>.isSafeInteger()</span><br><span class="line">用于判断数值是否在安全范围内。</span><br><span class="line"><span class="built_in">Number</span>.isSafeInteger(<span class="built_in">Number</span>.MIN_SAFE_INTEGER - <span class="number">1</span>); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Number</span>.isSafeInteger(<span class="built_in">Number</span>.MAX_SAFE_INTEGER + <span class="number">1</span>); <span class="comment">// false</span></span><br></pre></td></tr></table></figure></li>
<li>Math对象的扩展</li>
</ol>
<ul>
<li>Math.cbrt()  立方根</li>
<li>Math.imul() 以32位带符号整数形式相乘</li>
<li>Math.hypot 计算所有参数的平方和的立方根</li>
<li>Math.clz32() 用于返回数字的32位无符号整数形式的前导0的个数</li>
<li>Math.trunc() 用于返回数字的整数部分</li>
<li>Math.fround() 用于获取数字的32位单精度浮点形式</li>
<li>Math.sign() 判断符号</li>
<li>Math.exam() e的x次方-1的结果</li>
<li>指数运算符<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span> ** <span class="number">2</span>; <span class="comment">// 1的平方等于1</span></span><br><span class="line"><span class="comment">// 右结合，从右至左计算</span></span><br><span class="line"><span class="comment">//先算2的三次方等于8，再算2的8次方等于256</span></span><br><span class="line"><span class="number">2</span> ** <span class="number">2</span> ** <span class="number">3</span>; <span class="comment">// 256</span></span><br><span class="line"><span class="comment">// **=</span></span><br><span class="line"><span class="keyword">let</span> exam = <span class="number">2</span>;</span><br><span class="line">exam ** = <span class="number">2</span>; <span class="comment">// 4</span></span><br></pre></td></tr></table></figure>
<h1 id="ES6-对象"><a href="#ES6-对象" class="headerlink" title="ES6 对象"></a>ES6 对象</h1></li>
</ul>
<ol>
<li>对象字面量<br>属性的简洁表示法:ES6允许对象的属性直接写变量，这时候属性名是变量名，属性值是变量值<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> age = <span class="number">12</span>;</span><br><span class="line"><span class="keyword">const</span> name = <span class="string">"Amy"</span>;</span><br><span class="line"><span class="keyword">const</span> person = &#123;age, name&#125;;</span><br><span class="line">person   <span class="comment">//&#123;age: 12, name: "Amy"&#125;</span></span><br><span class="line"><span class="comment">//等同于</span></span><br><span class="line"><span class="keyword">const</span> person = &#123;<span class="attr">age</span>: age, <span class="attr">name</span>: name&#125;</span><br></pre></td></tr></table></figure></li>
<li>属性名表达式<br>ES6允许使用表达式作为属性名，但是一定要将表达式放在方括号内<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123;</span><br><span class="line"> [<span class="string">"he"</span>+<span class="string">"llo"</span>]()&#123;</span><br><span class="line">   <span class="keyword">return</span> <span class="string">"Hi"</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">obj.hello();  <span class="comment">//"Hi"</span></span><br></pre></td></tr></table></figure>
属性的简洁表示法和属性名表达式不能同时使用<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> hello = <span class="string">"Hello"</span>;</span><br><span class="line"><span class="keyword">const</span> obj = &#123;</span><br><span class="line"> [hello]</span><br><span class="line">&#125;;</span><br><span class="line">obj  <span class="comment">//SyntaxError: Unexpected token &#125;</span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">const</span> hello = <span class="string">"Hello"</span>;</span><br><span class="line"><span class="keyword">const</span> obj = &#123;</span><br><span class="line"> [hello+<span class="string">"2"</span>]:<span class="string">"world"</span></span><br><span class="line">&#125;;</span><br><span class="line">obj  <span class="comment">//&#123;Hello2: "world"&#125;</span></span><br></pre></td></tr></table></figure></li>
<li>对象的新方法 Object.assign(target,source_1,…)</li>
</ol>
<ul>
<li>用于将源对象的所有可枚举属性复制到目标对象中</li>
<li>第一个参数是目标对象，后面的参数是源对象<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> target = &#123;<span class="attr">a</span>: <span class="number">1</span>&#125;;</span><br><span class="line"><span class="keyword">let</span> object2 = &#123;<span class="attr">b</span>: <span class="number">2</span>&#125;;</span><br><span class="line"><span class="keyword">let</span> object3 = &#123;<span class="attr">c</span>: <span class="number">3</span>&#125;;</span><br><span class="line"><span class="built_in">Object</span>.assign(target,object2,object3);  </span><br><span class="line"><span class="comment">// 第一个参数是目标对象，后面的参数是源对象</span></span><br><span class="line">target;  <span class="comment">// &#123;a: 1, b: 2, c: 3</span></span><br></pre></td></tr></table></figure></li>
<li>如果目标对象和源对象用同名属性，或者多个源对象有同名属性，则后面的会覆盖前面的<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">targetObj = &#123; <span class="attr">a</span>: &#123; <span class="attr">b</span>: <span class="number">1</span>, <span class="attr">c</span>:<span class="number">2</span>&#125;&#125;;</span><br><span class="line">sourceObj = &#123; <span class="attr">a</span>: &#123; <span class="attr">b</span>: <span class="string">"hh"</span>&#125;&#125;;</span><br><span class="line"><span class="built_in">Object</span>.assign(targetObj, sourceObj);</span><br><span class="line">targetObj;  <span class="comment">// &#123;a: &#123;b: "hh"&#125;&#125;</span></span><br></pre></td></tr></table></figure></li>
<li>如果该函数只有一个参数，当参数为对象时，直接返回该对象，当参数不是对象时，先将参数转为对象然后再返回]<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Object</span>.assign(<span class="number">3</span>);         <span class="comment">// Number &#123;3&#125;</span></span><br><span class="line"><span class="keyword">typeof</span> <span class="built_in">Object</span>.assign(<span class="number">3</span>);  <span class="comment">// "object"</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Object</span>.assign(<span class="literal">null</span>);       <span class="comment">// TypeError: Cannot convert undefined or null to object</span></span><br><span class="line"><span class="built_in">Object</span>.assign(<span class="literal">undefined</span>);  <span class="comment">// TypeError: Cannot convert undefined or null to object</span></span><br><span class="line">当参数不止一个时，<span class="literal">null</span> 和 <span class="literal">undefined</span> 不放第一个，即不为目标对象时，会跳过 <span class="literal">null</span> 和 <span class="literal">undefined</span> ，不报错</span><br><span class="line"><span class="built_in">Object</span>.assign(<span class="number">1</span>,<span class="literal">undefined</span>);  <span class="comment">// Number &#123;1&#125;</span></span><br><span class="line"><span class="built_in">Object</span>.assign(&#123;<span class="attr">a</span>: <span class="number">1</span>&#125;,<span class="literal">null</span>);  <span class="comment">// &#123;a: 1&#125;</span></span><br><span class="line"> </span><br><span class="line"><span class="built_in">Object</span>.assign(<span class="literal">undefined</span>,&#123;<span class="attr">a</span>: <span class="number">1</span>&#125;);  <span class="comment">// TypeError: Cannot convert undefined or null to object</span></span><br></pre></td></tr></table></figure></li>
<li>是浅拷贝(改变目标的属性值，源也会变)<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> sourceObj = &#123; <span class="attr">a</span>: &#123; <span class="attr">b</span>: <span class="number">1</span>&#125;&#125;;</span><br><span class="line"><span class="keyword">let</span> targetObj = &#123;<span class="attr">c</span>: <span class="number">3</span>&#125;;</span><br><span class="line"><span class="built_in">Object</span>.assign(targetObj, sourceObj);</span><br><span class="line">targetObj.a.b = <span class="number">2</span>;</span><br><span class="line">sourceObj.a.b;  <span class="comment">// 2</span></span><br></pre></td></tr></table></figure></li>
<li>数组的处理<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Object</span>.assign([<span class="number">2</span>,<span class="number">3</span>], [<span class="number">5</span>]);  <span class="comment">// [5,3]</span></span><br></pre></td></tr></table></figure>
会将数组处理成对象，所以先将 [2,3] 转为 {0:2,1:3} ，然后再进行属性复制，所以源对象的 0 号属性覆盖了目标对象的 0</li>
</ul>
<ol start="4">
<li>Object.is(value1,value2)</li>
</ol>
<ul>
<li>用来比较两个值是否严格相等，类似于绝对等于(===)</li>
<li>基本用法<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Object</span>.is(<span class="string">"q"</span>,<span class="string">"q"</span>);      <span class="comment">// true</span></span><br><span class="line"><span class="built_in">Object</span>.is(<span class="number">1</span>,<span class="number">1</span>);          <span class="comment">// true</span></span><br><span class="line"><span class="built_in">Object</span>.is([<span class="number">1</span>],[<span class="number">1</span>]);      <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Object</span>.is(&#123;<span class="attr">q</span>:<span class="number">1</span>&#125;,&#123;<span class="attr">q</span>:<span class="number">1</span>&#125;);  <span class="comment">// false</span></span><br></pre></td></tr></table></figure></li>
<li>与(===)的区别<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//一是+0不等于-0</span></span><br><span class="line"><span class="built_in">Object</span>.is(+<span class="number">0</span>,<span class="number">-0</span>);  <span class="comment">//false</span></span><br><span class="line">+<span class="number">0</span> === <span class="number">-0</span>  <span class="comment">//true</span></span><br><span class="line"><span class="comment">//二是NaN等于本身</span></span><br><span class="line"><span class="built_in">Object</span>.is(<span class="literal">NaN</span>,<span class="literal">NaN</span>); <span class="comment">//true</span></span><br><span class="line"><span class="literal">NaN</span> === <span class="literal">NaN</span>  <span class="comment">//false</span></span><br></pre></td></tr></table></figure>
<h1 id="ES6-数组"><a href="#ES6-数组" class="headerlink" title="ES6 数组"></a>ES6 数组</h1></li>
</ul>
<ol>
<li>数组创建 Array.of() 将参数中所有元素形成数组<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.of(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)); <span class="comment">// [1, 2, 3, 4]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 参数值可为不同类型</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.of(<span class="number">1</span>, <span class="string">'2'</span>, <span class="literal">true</span>)); <span class="comment">// [1, '2', true]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 参数为空时返回空数组</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.of()); <span class="comment">// []</span></span><br></pre></td></tr></table></figure></li>
<li>Array.from() 将类数组对象或可迭代对象转化为数组<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数为数组,返回与原数组一样的数组</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.from([<span class="number">1</span>, <span class="number">2</span>])); <span class="comment">// [1, 2]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 参数含空位</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.from([<span class="number">1</span>, , <span class="number">3</span>])); <span class="comment">// [1, undefined, 3]</span></span><br></pre></td></tr></table></figure>
可接受三个参数Array.from(arrayLike,mapFn,thisArg),arrayLike类数组对象或者可迭代对象，mapFn传入处理每一个元素的map函数，为可选参数，thisArg用于指定map函数执行时的this对象，也为可选参数<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> map = &#123;</span><br><span class="line">    <span class="keyword">do</span>: <span class="function"><span class="keyword">function</span>(<span class="params">n</span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> n * <span class="number">2</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> arrayLike = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.from(arrayLike, <span class="function"><span class="keyword">function</span> (<span class="params">n</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">this</span>.do(n);</span><br><span class="line">&#125;, map)); <span class="comment">// [2, 4, 6]</span></span><br></pre></td></tr></table></figure>
类数组对象:一个类数组对象必须含有 length 属性，且元素属性名必须是数值或者可转换为数值的字符<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> arr = <span class="built_in">Array</span>.from(&#123;</span><br><span class="line">  <span class="number">0</span>: <span class="string">'1'</span>,</span><br><span class="line">  <span class="number">1</span>: <span class="string">'2'</span>,</span><br><span class="line">  <span class="number">2</span>: <span class="number">3</span>,</span><br><span class="line">  length: <span class="number">3</span></span><br><span class="line">&#125;);</span><br><span class="line"><span class="built_in">console</span>.log(arr); <span class="comment">// ['1', '2', 3]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 没有 length 属性,则返回空数组</span></span><br><span class="line"><span class="keyword">let</span> array = <span class="built_in">Array</span>.from(&#123;</span><br><span class="line">  <span class="number">0</span>: <span class="string">'1'</span>,</span><br><span class="line">  <span class="number">1</span>: <span class="string">'2'</span>,</span><br><span class="line">  <span class="number">2</span>: <span class="number">3</span>,</span><br><span class="line">&#125;);</span><br><span class="line"><span class="built_in">console</span>.log(array); <span class="comment">// []</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 元素属性名不为数值且无法转换为数值，返回长度为 length 元素值为 undefined 的数组  </span></span><br><span class="line"><span class="keyword">let</span> array1 = <span class="built_in">Array</span>.from(&#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: <span class="number">2</span>,</span><br><span class="line">  length: <span class="number">2</span></span><br><span class="line">&#125;);</span><br><span class="line"><span class="built_in">console</span>.log(array1); <span class="comment">// [undefined, undefined]</span></span><br></pre></td></tr></table></figure></li>
<li>扩展的方法<br>find() 查找符合条件的第一个元素并返回<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> arr = <span class="built_in">Array</span>.of(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>);</span><br><span class="line"><span class="built_in">console</span>.log(arr.find(<span class="function"><span class="params">item</span> =&gt;</span> item &gt; <span class="number">2</span>)); <span class="comment">// 3</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 数组空位处理为 undefined</span></span><br><span class="line"><span class="built_in">console</span>.log([, <span class="number">1</span>].find(<span class="function"><span class="params">n</span> =&gt;</span> <span class="literal">true</span>)); <span class="comment">// undefined</span></span><br></pre></td></tr></table></figure>
findIndex() 查找符合条件的第一个元素并返回其索引<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> arr = <span class="built_in">Array</span>.of(<span class="number">1</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">3</span>);</span><br><span class="line"><span class="comment">// 参数1：回调函数</span></span><br><span class="line"><span class="comment">// 参数2(可选)：指定回调函数中的 this 值</span></span><br><span class="line"><span class="built_in">console</span>.log(arr.findIndex(<span class="function"><span class="params">item</span> =&gt;</span> item = <span class="number">1</span>)); <span class="comment">// 0</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 数组空位处理为 undefined</span></span><br><span class="line"><span class="built_in">console</span>.log([, <span class="number">1</span>].findIndex(<span class="function"><span class="params">n</span> =&gt;</span> <span class="literal">true</span>)); <span class="comment">//0</span></span><br></pre></td></tr></table></figure>
fill() 将一定索引范围内的数组元素填充为单个指定的值<br>参数1：用来填充的值<br>参数2：起始索引<br>参数3：结束索引，可选，默认到末尾<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> arr = <span class="built_in">Array</span>.of(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>);</span><br><span class="line"><span class="comment">// 参数1：用来填充的值</span></span><br><span class="line"><span class="comment">// 参数2：被填充的起始索引</span></span><br><span class="line"><span class="comment">// 参数3(可选)：被填充的结束索引，默认为数组末尾</span></span><br><span class="line"><span class="built_in">console</span>.log(arr.fill(<span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>)); <span class="comment">// [1, 0, 3, 4]</span></span><br></pre></td></tr></table></figure>
copyWithin() 将数组一定范围内的元素修改为此数组另一索引范围的元素<br>参数1：被修改的起始索引<br>参数2：被用来覆盖的数据的起始索引<br>参数3：可选，被用来覆盖数据的结束索引，默认数组末尾<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数1：被修改的起始索引</span></span><br><span class="line"><span class="comment">// 参数2：被用来覆盖的数据的起始索引</span></span><br><span class="line"><span class="comment">// 参数3(可选)：被用来覆盖的数据的结束索引，默认为数组末尾</span></span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].copyWithin(<span class="number">0</span>,<span class="number">2</span>,<span class="number">4</span>)); <span class="comment">// [3, 4, 3, 4]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 参数1为负数表示倒数</span></span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].copyWithin(<span class="number">-2</span>, <span class="number">0</span>)); <span class="comment">// [1, 2, 1, 2]</span></span><br><span class="line"> </span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, <span class="number">2</span>, ,<span class="number">4</span>].copyWithin(<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>)); <span class="comment">// [, 4, , 4]</span></span><br></pre></td></tr></table></figure>
entries()   返回键值对<br>keys()      返回键<br>values()   返回值<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> [key, value] <span class="keyword">of</span> [<span class="string">'a'</span>, <span class="string">'b'</span>].entries())&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(key, value);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 0 "a"</span></span><br><span class="line"><span class="comment">// 1 "b"</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 不使用 for... of 循环</span></span><br><span class="line"><span class="keyword">let</span> entries = [<span class="string">'a'</span>, <span class="string">'b'</span>].entries();</span><br><span class="line"><span class="built_in">console</span>.log(entries.next().value); <span class="comment">// [0, "a"]</span></span><br><span class="line"><span class="built_in">console</span>.log(entries.next().value); <span class="comment">// [1, "b"]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 数组含空位</span></span><br><span class="line"><span class="built_in">console</span>.log([...[,<span class="string">'a'</span>].entries()]); <span class="comment">// [[0, undefined], [1, "a"]]</span></span><br></pre></td></tr></table></figure>
includes() 数组是否包含指定值，返回boolean值<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数1：包含的指定值</span></span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].includes(<span class="number">1</span>);    <span class="comment">// true</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 参数2：可选，搜索的起始索引，默认为0</span></span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].includes(<span class="number">1</span>, <span class="number">2</span>); <span class="comment">// false</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// NaN 的包含判断</span></span><br><span class="line">[<span class="number">1</span>, <span class="literal">NaN</span>, <span class="number">3</span>].includes(<span class="literal">NaN</span>); <span class="comment">// true</span></span><br></pre></td></tr></table></figure>
flat() 嵌套数组转一维数组<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span> ,[<span class="number">2</span>, <span class="number">3</span>]].flat()); <span class="comment">// [1, 2, 3]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 指定转换的嵌套层数</span></span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, [<span class="number">2</span>, [<span class="number">3</span>, [<span class="number">4</span>, <span class="number">5</span>]]]].flat(<span class="number">2</span>)); <span class="comment">// [1, 2, 3, [4, 5]]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 不管嵌套多少层</span></span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, [<span class="number">2</span>, [<span class="number">3</span>, [<span class="number">4</span>, <span class="number">5</span>]]]].flat(<span class="literal">Infinity</span>)); <span class="comment">// [1, 2, 3, 4, 5]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">// 自动跳过空位</span></span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, [<span class="number">2</span>, , <span class="number">3</span>]].flat());<span class="xml"><span class="tag">&lt;<span class="name">p</span>&gt;</span> // [1, 2, 3]</span></span><br></pre></td></tr></table></figure>
flatMap() 先对每个元素进行处理，再执行flat()<br>参数1：遍历函数，该遍历函数接受3个参数(当前元素、当前元素索引、原数组)<br>参数2：指定遍历函数中this的指向<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数1：遍历函数，该遍历函数可接受3个参数：当前元素、当前元素索引、原数组</span></span><br><span class="line"><span class="comment">// 参数2：指定遍历函数中 this 的指向</span></span><br><span class="line"><span class="built_in">console</span>.log([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].flatMap(<span class="function"><span class="params">n</span> =&gt;</span> [n * <span class="number">2</span>])); <span class="comment">// [2, 4, 6]</span></span><br></pre></td></tr></table></figure>
总结自菜鸟教程，更多详细内容，可查看官方网页<br><a href="https://www.runoob.com/w3cnote/es6-tutorial.html" target="_blank" rel="noopener">跳转</a><br>我的分享就到这里了，谢谢大家</li>
</ol>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://lockme.gitee.io/2020/05/14/Es6-one-md/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ES6/" rel="tag">ES6</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JavaScript/" rel="tag">JavaScript</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%8A%80%E6%9C%AF/" rel="tag">技术</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/05/14/Es6-two-md/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            Es6_two.md
          
        </div>
      </a>
    
    
      <a href="/2020/04/12/JS-HTML-DOM-md/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">JS HTML DOM.md</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'pmaQYnbUE9O0H1hiYKLiec4R-gzGzoHsz',
        app_key: 'LMujtI79W4vgEQ3Az5IMo50y',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020
        月下ctrlc
      </li>
      <li>
        
        Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
    <aside class="sidebar">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/avatar.jpg" alt="Small Bridge"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Vue/">Vue</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="http://shenyu-vip.lofter.com" target="_blank" rel="noopener">主题作者相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/03/18/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>拿钱砸死我吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.png">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/share.js"></script>


<script src="/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/js/ayer.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>



<script src="/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>


    
  </div>
</body>

</html>